<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/import.jsp"%>
<%@ include file="function.jsp"%>
<%
	List<Map> ranks = QBuilder.db("basedb").select("new map(i.id as id, i.name as item_name, i.principal as principal, i.version_type as version_type, i.item_type as item_type, i.design_leader as design_leader, i.developer as developer, i.sale_leader as sale_leader, i.sale_manager as sale_manager, i.start_time as start_time, i.end_time as end_time, i.description as description, i.remark as remark, p.name as hospital_name, i.status as status, i.state as state)").from("project as i, Hospital as p").where(new Where("i.status=", STATUS_ENABLE).and("p.hospital=i.hospital")).order("i.end_time", "asc").query().getResultObj();
	Integer yiLiXiang = 0;
	Integer yiJieXiang = 0;
	Integer yanQiYiBiaoShi = 0;
	Integer yanQiWeiBiaoShi = 0;
	List<Map> exceptionList = new ArrayList<Map>();
	for (Map map:ranks) {
		String state = Tools.getDesc(map.get("state"));
		Long endTime = (Long)map.get("end_time");
		if (endTime < System.currentTimeMillis() && "已立项".equals(state)) {
			yanQiWeiBiaoShi++;
			exceptionList.add(map);
		}
		Long s = (endTime - System.currentTimeMillis()) / (1000 * 60*60*24);
		map.put("have", s);
		if ("已立项".equals(state))
			yiLiXiang++;
		if ("已结项".equals(state))
			yiJieXiang++;
		if ("延期".equals(state))
			yanQiYiBiaoShi++;
	}
	String message = String.format("截止目前(%s)，共承接了%s个项目，其中%s已立项，%s个已结项，%s个已标识延期, %s个未标识但已经延期。", new Object[]{DateUtil.formatDate(new Date()),ranks.size(),yiLiXiang, yiJieXiang, yanQiYiBiaoShi, yanQiWeiBiaoShi});
	msg.put("result", message);
	List<String> list = new ArrayList<>();
	for (Map map:ranks) {
		String desc = "已延期";
		long have = (long)map.get("have");
		if (have >= 0 && have < 5)
			desc = "仅剩";
		if (have >=5 )
			desc = "还剩";
		String detail = String.format("《%s》%s天", new Object[]{map.get("hospital_name") + "" + map.get("item_name"), desc+Math.abs(have), DateUtil.formatDate(new Date((long)map.get("start_time"))), DateUtil.formatDate(new Date((long)map.get("end_time")))});
		if (!Tools.getDesc(map.get("state")).equals("已结项")) 
			list.add(detail);
	}
	msg.put("detail", list);
	Tools.print(out, msg);
%>
